From a38a449ab78a4e8ab56705922f5c13f9365a92a4 Mon Sep 17 00:00:00 2001
From: Owen Jacobson <owen@grimoire.ca>
Date: Wed, 14 May 2025 00:55:34 -0400
Subject: Don't try to update last read time for channel pages if the channel
 has vanished.

This may happen if the user has a link to a channel open when the channel is deleted/expires, or if they return to the app after the last channel they looked at has expired.
---
 ui/routes/(app)/ch/[channel]/+page.svelte | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

(limited to 'ui/routes/(app)/ch/[channel]/+page.svelte')

diff --git a/ui/routes/(app)/ch/[channel]/+page.svelte b/ui/routes/(app)/ch/[channel]/+page.svelte
index ea8cca6..76bb638 100644
--- a/ui/routes/(app)/ch/[channel]/+page.svelte
+++ b/ui/routes/(app)/ch/[channel]/+page.svelte
@@ -46,8 +46,10 @@
 
   function setLastRead() {
     const lastInView = getLastVisibleMessage();
-    const at = !!lastInView ? DateTime.fromISO(lastInView.dataset.at) : channel.at;
-    session.local.updateLastReadAt(channelId, at);
+    const at = !!lastInView ? DateTime.fromISO(lastInView.dataset.at) : channel?.at;
+    if (!!at) {
+      session.local.updateLastReadAt(channelId, at);
+    }
   }
 
   $effect(() => {
-- 
cgit v1.2.3

